<?php

require_once ('lib/class.http.php');
require_once ('lib/class.urls.php');
require_once ('lib/dump.php');
include_once ('lib/parvis.constants.php');


// Retrouver la langue de l'URL
$langage = urls::getLangNum();

$articleID = $_GET['id'];

if($articleID == "" || $articleID == null || strlen($articleID) > 15){
	print $_GET['trad'];
}else{
	$api = new Http();
	$api->debug = $debug;
	ob_start();

	//$url = 'http://parvis.ch/cgi-bin/cgiip.exe/WService=wsbroker1/.w';//?lang='.$langage.'&id=' . $articleID
	$url = sprintf('%stbr_fiche.w', WEBSPEED);

	$api->useCurl(false);

	$api->setMethod('GET');
	$api->addParam('lang', $langage);
	$api->addParam('id', $articleID);

	$api->useCookie(true);
	$api->saveCookie(true);
	//$api->addCookie('SessionId', $_COOKIE['SessionId']);
	//$api->addCookie('InterNou', $_COOKIE['InterNou']);


	$api->execute($url);

	$cookies = $api->_cookies;

	if ($debug) {
			dump($cookies, 'Cookies retourné par le serveur');

			dump($cookies[0]['value'], 'value');
	}

	echo ($api->error) ? $api->error : utf8_encode($api->result);
	$content = ob_get_contents();
	ob_end_clean();
	preg_match_all("'<h1 class=\"relations\">(.*?)</h1>'si", $content, $match);
	$title = "";
    foreach($match[1] as $val){
        $title  = $val;
		break;
	}
	/*
	Changer le titre de la page avant le rendu... (pas en javascript) SEO friendly
	*/
	//$article_title = explode("/",$_SERVER['REQUEST_URI']);
	drupal_set_title(urldecode($title).' - '.$articleID);	
	echo"$content";
	
}
?>